package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.utils.MailUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZhwyUrge;
import com.ruoyi.system.service.IZhwyUrgeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 费用催缴Controller
 * 
 * @author nhh
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/system/urge")
public class ZhwyUrgeController extends BaseController
{
    @Autowired
    private IZhwyUrgeService zhwyUrgeService;

    @Anonymous
    @GetMapping("/sendemail")
    public void sendEmail()
    {
        MailUtils.sendMail("1366077207@qq.com","这是一条催缴邮件，请及时缴费！","催缴费用");

    }

    /**
     * 查询费用催缴列表
     */
    @PreAuthorize("@ss.hasPermi('system:urge:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZhwyUrge zhwyUrge)
    {
        startPage();
        List<ZhwyUrge> list = zhwyUrgeService.selectZhwyUrgeList(zhwyUrge);
        return getDataTable(list);
    }

    /**
     * 导出费用催缴列表
     */
    @PreAuthorize("@ss.hasPermi('system:urge:export')")
    @Log(title = "费用催缴", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZhwyUrge zhwyUrge)
    {
        List<ZhwyUrge> list = zhwyUrgeService.selectZhwyUrgeList(zhwyUrge);
        ExcelUtil<ZhwyUrge> util = new ExcelUtil<ZhwyUrge>(ZhwyUrge.class);
        util.exportExcel(response, list, "费用催缴数据");
    }

    /**
     * 获取费用催缴详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:urge:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zhwyUrgeService.selectZhwyUrgeById(id));
    }

    /**
     * 新增费用催缴
     */
    @PreAuthorize("@ss.hasPermi('system:urge:add')")
    @Log(title = "费用催缴", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhwyUrge zhwyUrge)
    {
        return toAjax(zhwyUrgeService.insertZhwyUrge(zhwyUrge));
    }

    /**
     * 修改费用催缴
     */
    @PreAuthorize("@ss.hasPermi('system:urge:edit')")
    @Log(title = "费用催缴", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhwyUrge zhwyUrge)
    {
        return toAjax(zhwyUrgeService.updateZhwyUrge(zhwyUrge));
    }

    /**
     * 删除费用催缴
     */
    @PreAuthorize("@ss.hasPermi('system:urge:remove')")
    @Log(title = "费用催缴", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zhwyUrgeService.deleteZhwyUrgeByIds(ids));
    }
}
